<?php

/**
 * category actions.
 *
 * @package    emc
 * @subpackage category
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class categoryActions extends sfActions
{
	/**
	* Executes index action
	*
	* @param sfRequest $request A request object
	*/
	public function executeIndex(sfWebRequest $request)
	{
		$this->forward('default', 'module');
	}
	
	public function executeView(sfWebRequest $request)
	{
		// Change Language
		if (!$request->getParameter('sf_culture'))
		{
			if ($this->getUser()->isFirstRequest())
			{
				$culture = $request->getPreferredCulture(array('vi', 'en'));
				$this->getUser()->setCulture($culture);
				$this->getUser()->isFirstRequest(false);
			}
			else
			{
				$culture = $this->getUser()->getCulture();
			}
		}
		
		$category_id = $request->getParameter("category_id");
		if (preg_match("/^[0-9]+/", $category_id, $match))
			$category_id = $match[0];
		
		$current_category = Doctrine_Core::getTable("Category")->find($category_id);
		$products = array();
		$current_category->getProducts($products);
		
		$this->current_category = $current_category;
		$this->products = $products;
		
		return sfView::SUCCESS;
	}
}
